Description:
static
members should be referenced by the names
of classes where these members are defined.
If a static
member is referenced through a descendant type,
an error message is generated.
Incorrect:
public class Animal {
public static int populationCount;
}
public class Elephant : Animal {
}
int getPopulation() {
return Elephant.populationCount;
}
Correct:
public class Animal {
public static int populationCount;
}
public class Elephant : Animal {
}
int getPopulation() {
return Animal.populationCount;
}